//------------------------------------------------------------------------------
// <copyright file="AbstractHero.cs" company="Damian Antonowicz">
//       copyright © 2010 Damian Antonowicz
// </copyright>
// <author>Damian Antonowicz</author>
// <email>poczta@damianantonowicz.pl</email>
//------------------------------------------------------------------------------

using System;
using System.Xml.Serialization;
using System.IO;
using DAnton.Utilities.Helpers;
using System.ComponentModel;

namespace DotBeer.Business.Entities
{
    public class AbstractHero : INotifyPropertyChanged
    {
        #region private members

        protected string name;
        protected Side side;

        #endregion

        #region properties

        public string Name
        {
            set
            {
                this.name = value;
                this.OnPropertyChanged("Name");
                this.OnPropertyChanged("ImagePath");
            }
            get { return this.name; }
        }

        public Side Side
        {
            set
            {
                this.side = value;
                this.OnPropertyChanged("Side");
            }
            get { return this.side; }
        }

        [XmlIgnore]
        public string ImagePath
        {
            get { return this.GetImagePath(); }
            set { this.SetImage(value); }
        }

        #endregion

        #region public methods

        public override string ToString()
        {
            return this.name;
        }

        #endregion

        #region private methods

        private string GetImagePath()
        {
            return String.Format("{0}Images\\Heroes\\{1}.GIF", IOHelper.ApplicationStartupPath, this.name);
        }

        private void SetImage(string newFileName)
        {
            File.Copy(newFileName, this.GetImagePath());
            this.OnPropertyChanged("ImagePath");
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Notify that property was changed.
        /// </summary>
        /// <param this.name="info">Changed property this.name</param>
        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

        #endregion
    }
}
